public class hdu1212(简单大数题){
    public static void main(String[]args){
        Scanner s=new Scanner(System.in);
        BigInteger a;
        BigInteger b;
        while(s.hasNextBigInteger()){
            a=s.nextBigInteger();
            b=s.nextBigInteger();
            System.out.println(a.mod(b));
        }
    }
}